package com.guguskins.back.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guguskins.back.entity.GuCarouselMap;
import com.guguskins.back.mapper.GuCarouselMapMapper;
import com.guguskins.back.service.GuCarouselMapService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * <p>
 * 轮播图表 服务实现类
 * </p>
 *
 * @author mybatis-plus
 * @since 2021-07-08
 */
@Service
public class GuCarouselMapServiceImpl extends ServiceImpl<GuCarouselMapMapper, GuCarouselMap> implements GuCarouselMapService {
    @Autowired
    private GuCarouselMapMapper guCarouselMapMapper;

    @Override
    public GuCarouselMap findById(Integer cmId) {
        LambdaQueryWrapper<GuCarouselMap> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GuCarouselMap::getCmId,cmId);
        return guCarouselMapMapper.selectOne(queryWrapper);
    }


    @Override
    public List<GuCarouselMap> availableList(Integer cmType) {
        LambdaQueryWrapper<GuCarouselMap> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(GuCarouselMap::getCmEnable, true);
        queryWrapper.eq(GuCarouselMap::getCmType,cmType);
        return guCarouselMapMapper.selectList(queryWrapper);
    }

    @Override
    public List<GuCarouselMap> findByCmType(Integer cmType) {
        if(cmType==0){
            LambdaQueryWrapper<GuCarouselMap> queryWrapper=new LambdaQueryWrapper();
            return  guCarouselMapMapper.selectList(queryWrapper);
        }
        LambdaQueryWrapper<GuCarouselMap> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(GuCarouselMap::getCmType,cmType);
        return  guCarouselMapMapper.selectList(queryWrapper);
    }

    @Override
    public void insert(GuCarouselMap carouselMap) {

        guCarouselMapMapper.insert(carouselMap);

    }

}
